home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / Zoom / Zoom.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  10.2 KB  |  489 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Cursor;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.MediaTracker;
  11. import java.awt.event.MouseEvent;
  12. import java.awt.event.MouseListener;
  13. import java.net.MalformedURLException;
  14. import java.net.URL;
  15. import java.net.URLEncoder;
  16.  
  17. public class Zoom extends Applet implements Runnable, MouseListener {
  18.    private Thread thread;
  19.    private Image buffer;
  20.    private Image backImage;
  21.    private Image[] image;
  22.    // $FF: renamed from: b java.awt.Graphics
  23.    private Graphics field_0;
  24.    private boolean loaded;
  25.    private int wiBack;
  26.    private int heBack;
  27.    private boolean isBackImage = false;
  28.    private boolean move = true;
  29.    // $FF: renamed from: on boolean
  30.    private boolean field_1 = true;
  31.    // $FF: renamed from: n int
  32.    private int field_2;
  33.    private int n_im = 1;
  34.    // $FF: renamed from: wi int
  35.    private int field_3;
  36.    // $FF: renamed from: he int
  37.    private int field_4;
  38.    private int[] wi_im;
  39.    private int[] he_im;
  40.    private float wiz;
  41.    private float hez;
  42.    private int pause = 50;
  43.    private int pause2 = 1000;
  44.    private int zoom_min = 4;
  45.    private int zoom_max;
  46.    private int step = 2;
  47.    // $FF: renamed from: X float
  48.    private float field_5;
  49.    // $FF: renamed from: Y float
  50.    private float field_6;
  51.    private int decx;
  52.    private int decy;
  53.    private String[] image_string;
  54.    private String backImageName;
  55.    private Color backColor;
  56.    private String statusBarText;
  57.    private AudioClip sound;
  58.    private AudioClip clicSound;
  59.    private AudioClip enterSound;
  60.    private boolean loopSound;
  61.    private String link;
  62.    // $FF: renamed from: fm java.awt.FontMetrics
  63.    private FontMetrics field_7;
  64.    private String enterText;
  65.    private boolean isEnterTextEnabled;
  66.    private int wiEnterText;
  67.    private int enterTextHeight;
  68.    private Color enterTextColor;
  69.  
  70.    public String getAppletInfo() {
  71.       return "Name: Zoom\r\nAuthor: Taiji Software\r\n";
  72.    }
  73.  
  74.    public Zoom() {
  75.       ((Component)this).addMouseListener(this);
  76.    }
  77.  
  78.    public void register() {
  79.       try {
  80.          URL u = new URL("http://www.taijisoftware.com");
  81.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  82.       } catch (Exception e) {
  83.          System.out.println(e);
  84.          this.stop();
  85.       }
  86.    }
  87.  
  88.    public void init() {
  89.       String codeBase = null;
  90.  
  91.       try {
  92.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  93.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  94.          codeBase = codeBase.toUpperCase();
  95.       } catch (Exception var8) {
  96.       }
  97.  
  98.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  99.          String regCode = ((Applet)this).getParameter("registration_code");
  100.          if (regCode == null) {
  101.             regCode = ((Applet)this).getParameter("reg_domain");
  102.             if (regCode == null) {
  103.                this.register();
  104.             } else {
  105.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  106.                   codeBase = "WWW." + codeBase;
  107.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  108.                   codeBase = codeBase.substring(4);
  109.                }
  110.  
  111.                char[] chars = new char[codeBase.length()];
  112.                codeBase.getChars(0, codeBase.length(), chars, 0);
  113.                String key = new String("haricot");
  114.                char[] chars2 = new char[key.length()];
  115.                key.getChars(0, key.length(), chars2, 0);
  116.  
  117.                for(int i = 0; i < codeBase.length(); ++i) {
  118.                   int j;
  119.                   if (i >= key.length()) {
  120.                      j = i - key.length() * (i / key.length());
  121.                   } else {
  122.                      j = i;
  123.                   }
  124.  
  125.                   chars[i] += chars2[j];
  126.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  127.                }
  128.  
  129.                new String(chars);
  130.             }
  131.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  132.             this.register();
  133.          }
  134.       }
  135.  
  136.       this.move = true;
  137.       this.getParameters();
  138.       if (this.sound != null) {
  139.          if (this.loopSound) {
  140.             this.sound.loop();
  141.             return;
  142.          }
  143.  
  144.          this.sound.play();
  145.       }
  146.  
  147.    }
  148.  
  149.    public void getParameters() {
  150.       this.field_3 = ((Component)this).getSize().width;
  151.       this.field_4 = ((Component)this).getSize().height;
  152.       String s = ((Applet)this).getParameter("image_number");
  153.       if (s != null) {
  154.          this.n_im = Integer.parseInt(s);
  155.       }
  156.  
  157.       this.image_string = new String[this.n_im + 1];
  158.  
  159.       for(int i = 1; i <= this.n_im; ++i) {
  160.          this.image_string[i] = ((Applet)this).getParameter("image" + i);
  161.       }
  162.  
  163.       s = ((Applet)this).getParameter("pause");
  164.       if (s != null) {
  165.          this.pause = Integer.parseInt(s);
  166.       }
  167.  
  168.       s = ((Applet)this).getParameter("pause2");
  169.       if (s != null) {
  170.          this.pause2 = Integer.parseInt(s);
  171.       }
  172.  
  173.       s = ((Applet)this).getParameter("step");
  174.       if (s != null) {
  175.          this.step = Integer.parseInt(s);
  176.       }
  177.  
  178.       this.backImageName = ((Applet)this).getParameter("background_image");
  179.       if (this.backImageName != null) {
  180.          this.isBackImage = true;
  181.       }
  182.  
  183.       ((Component)this).setBackground(this.getColor("background_color"));
  184.       this.statusBarText = ((Applet)this).getParameter("status_bar_text");
  185.       s = ((Applet)this).getParameter("sound_name");
  186.       if (s != null) {
  187.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  188.       }
  189.  
  190.       s = ((Applet)this).getParameter("loop_sound");
  191.       if (s != null) {
  192.          if (s.equals("yes")) {
  193.             this.loopSound = true;
  194.          } else {
  195.             this.loopSound = false;
  196.          }
  197.       }
  198.  
  199.       s = ((Applet)this).getParameter("clic_sound_name");
  200.       if (s != null) {
  201.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  202.       }
  203.  
  204.       s = ((Applet)this).getParameter("enter_sound_name");
  205.       if (s != null) {
  206.          this.enterSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  207.       }
  208.  
  209.       this.link = ((Applet)this).getParameter("link");
  210.       this.enterText = ((Applet)this).getParameter("enter_text");
  211.       s = ((Applet)this).getParameter("enter_text_height");
  212.       if (s != null) {
  213.          this.enterTextHeight = Integer.parseInt(s);
  214.       }
  215.  
  216.       this.enterTextColor = this.getColor("enter_text_color");
  217.       if (this.enterTextColor == null) {
  218.          this.enterTextColor = Color.white;
  219.       }
  220.  
  221.    }
  222.  
  223.    public Color getColor(String param) {
  224.       String s = ((Applet)this).getParameter(param);
  225.       if (s != null) {
  226.          if (s.substring(0, 1).equals("#")) {
  227.             s = s.substring(1);
  228.             int i = Integer.parseInt(s, 16);
  229.             return new Color(i);
  230.          } else {
  231.             return null;
  232.          }
  233.       } else {
  234.          return null;
  235.       }
  236.    }
  237.  
  238.    public final void paint(Graphics g) {
  239.       if (this.loaded) {
  240.          this.field_0.clearRect(0, 0, this.field_3, this.field_4);
  241.          if (this.isBackImage) {
  242.             this.field_0.drawImage(this.backImage, (this.field_3 - this.wiBack) / 2, (this.field_4 - this.heBack) / 2, this);
  243.          }
  244.  
  245.          this.field_0.drawImage(this.image[this.field_2], (int)((float)this.decx + this.field_5), (int)((float)this.decy + this.field_6), (int)this.wiz, (int)this.hez, this);
  246.          if (this.isEnterTextEnabled) {
  247.             this.field_0.drawString(this.enterText, (this.field_3 - this.wiEnterText) / 2, this.field_4 / 2);
  248.          }
  249.  
  250.          g.drawImage(this.buffer, 0, 0, this);
  251.       }
  252.  
  253.    }
  254.  
  255.    public final void update(Graphics g) {
  256.       this.paint(g);
  257.    }
  258.  
  259.    public void start() {
  260.       if (this.thread == null) {
  261.          this.move = true;
  262.          this.thread = new Thread(this);
  263.          this.thread.start();
  264.       }
  265.  
  266.    }
  267.  
  268.    public void stop() {
  269.       if (this.thread != null) {
  270.          this.move = false;
  271.          this.thread = null;
  272.       }
  273.  
  274.       if (this.sound != null) {
  275.          this.sound.stop();
  276.       }
  277.  
  278.    }
  279.  
  280.    public void run() {
  281.       if (!this.loaded) {
  282.          this.image = new Image[this.n_im + 1];
  283.          this.wi_im = new int[this.n_im + 1];
  284.          this.he_im = new int[this.n_im + 1];
  285.          MediaTracker tracker = new MediaTracker(this);
  286.  
  287.          for(int i = 1; i <= this.n_im; ++i) {
  288.             this.image[i] = ((Applet)this).getImage(((Applet)this).getCodeBase(), this.image_string[i]);
  289.          }
  290.  
  291.          for(int i = 1; i <= this.n_im; ++i) {
  292.             tracker.addImage(this.image[i], 0);
  293.          }
  294.  
  295.          if (this.isBackImage) {
  296.             this.backImage = ((Applet)this).getImage(((Applet)this).getCodeBase(), this.backImageName);
  297.             tracker.addImage(this.backImage, 0);
  298.          }
  299.  
  300.          try {
  301.             tracker.waitForAll();
  302.             this.loaded = !tracker.isErrorAny();
  303.          } catch (Exception e) {
  304.             System.out.println(e);
  305.          }
  306.  
  307.          if (!this.loaded) {
  308.             this.stop();
  309.          }
  310.       }
  311.  
  312.       float[] rap = new float[this.n_im + 1];
  313.  
  314.       for(int i = 1; i <= this.n_im; ++i) {
  315.          this.wi_im[i] = this.image[i].getWidth(this);
  316.          this.he_im[i] = this.image[i].getHeight(this);
  317.          rap[i] = (float)this.he_im[i] / (float)this.wi_im[i];
  318.       }
  319.  
  320.       this.decx = (this.field_3 - this.wi_im[1]) / 2;
  321.       this.decy = (this.field_4 - this.he_im[1]) / 2;
  322.       this.buffer = ((Component)this).createImage(this.field_3, this.field_4);
  323.       this.field_0 = this.buffer.getGraphics();
  324.       this.field_0.setColor(this.enterTextColor);
  325.       String fontName = ((Applet)this).getParameter("enter_text_font");
  326.       if (fontName == null) {
  327.          fontName = "TimesRoman";
  328.       }
  329.  
  330.       int style = 1;
  331.       String s = ((Applet)this).getParameter("enter_text_style");
  332.       if (s != null) {
  333.          if (s.equals("bold")) {
  334.             style = 1;
  335.          } else if (s.equals("italic")) {
  336.             style = 2;
  337.          } else if (s.equals("bold_italic")) {
  338.             style = 3;
  339.          } else {
  340.             style = 0;
  341.          }
  342.       }
  343.  
  344.       this.field_0.setFont(new Font(fontName, style, this.enterTextHeight));
  345.       this.field_7 = this.field_0.getFontMetrics();
  346.       if (this.enterText != null) {
  347.          this.wiEnterText = this.field_7.stringWidth(this.enterText);
  348.       }
  349.  
  350.       if (this.isBackImage) {
  351.          this.wiBack = this.backImage.getWidth(this);
  352.          this.heBack = this.backImage.getHeight(this);
  353.       }
  354.  
  355.       this.field_2 = 1;
  356.       this.wiz = (float)this.wi_im[1];
  357.       this.hez = (float)this.he_im[1];
  358.       this.zoom_max = this.wi_im[1];
  359.  
  360.       while(this.move) {
  361.          while(this.field_1) {
  362.             this.wiz -= (float)(2 * this.step);
  363.             this.hez -= (float)(2 * this.step) * rap[this.field_2];
  364.             this.field_5 += (float)this.step;
  365.             this.field_6 += (float)this.step * rap[this.field_2];
  366.             ((Component)this).repaint();
  367.  
  368.             try {
  369.                Thread.sleep((long)this.pause);
  370.             } catch (InterruptedException var9) {
  371.                this.stop();
  372.             }
  373.  
  374.             if (this.wiz <= (float)(this.zoom_min + Math.abs(this.step))) {
  375.                this.step = -this.step;
  376.                ++this.field_2;
  377.                if (this.field_2 > this.n_im) {
  378.                   this.field_2 = 1;
  379.                }
  380.  
  381.                this.zoom_max = this.wi_im[this.field_2];
  382.                this.hez = rap[this.field_2] * this.wiz;
  383.             }
  384.  
  385.             if (this.wiz >= (float)this.zoom_max) {
  386.                this.step = -this.step;
  387.  
  388.                try {
  389.                   Thread.sleep((long)this.pause2);
  390.                } catch (InterruptedException var8) {
  391.                   this.stop();
  392.                }
  393.             }
  394.  
  395.             if (!this.field_1) {
  396.             }
  397.          }
  398.  
  399.          try {
  400.             Thread.sleep(100L);
  401.          } catch (InterruptedException var6) {
  402.             this.stop();
  403.          }
  404.       }
  405.  
  406.    }
  407.  
  408.    public URL giveURL(String url) {
  409.       try {
  410.          if (url.toUpperCase().startsWith("HTTP")) {
  411.             return new URL(url);
  412.          } else if (url.toUpperCase().startsWith("FTP")) {
  413.             int p = url.indexOf(":");
  414.             int p2 = url.indexOf(":", p + 1);
  415.             if (p2 != -1) {
  416.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  417.             }
  418.  
  419.             p = url.indexOf("%40");
  420.             if (p != -1) {
  421.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  422.             }
  423.  
  424.             return new URL(url);
  425.          } else {
  426.             return new URL(((Applet)this).getCodeBase(), url);
  427.          }
  428.       } catch (MalformedURLException e) {
  429.          System.out.println(e);
  430.          return null;
  431.       }
  432.    }
  433.  
  434.    public void mouseClicked(MouseEvent e) {
  435.    }
  436.  
  437.    public void mouseEntered(MouseEvent e) {
  438.       if (this.enterText != null) {
  439.          this.isEnterTextEnabled = true;
  440.          ((Component)this).repaint();
  441.       }
  442.  
  443.       if (this.statusBarText != null) {
  444.          ((Applet)this).showStatus(this.statusBarText);
  445.       }
  446.  
  447.       if (this.enterSound != null) {
  448.          this.enterSound.play();
  449.       }
  450.  
  451.       if (this.link != null) {
  452.          ((Component)this).setCursor(new Cursor(12));
  453.       }
  454.  
  455.    }
  456.  
  457.    public void mouseExited(MouseEvent e) {
  458.       if (this.isEnterTextEnabled) {
  459.          this.isEnterTextEnabled = false;
  460.          ((Component)this).repaint();
  461.       }
  462.  
  463.       if (this.link != null) {
  464.          ((Component)this).setCursor(new Cursor(0));
  465.       }
  466.  
  467.    }
  468.  
  469.    public void mousePressed(MouseEvent e) {
  470.       if (this.clicSound != null) {
  471.          this.clicSound.play();
  472.       }
  473.  
  474.       if (this.link != null) {
  475.          String target = ((Applet)this).getParameter("target");
  476.          if (target == null) {
  477.             target = "_blank";
  478.          }
  479.  
  480.          URL u = this.giveURL(this.link);
  481.          ((Applet)this).getAppletContext().showDocument(u, target);
  482.       }
  483.  
  484.    }
  485.  
  486.    public void mouseReleased(MouseEvent e) {
  487.    }
  488. }
  489.